package com.cadre.system.olddomain;

import org.dom4j.io.SAXReader;

import javax.servlet.http.HttpServletRequest;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;
import java.io.StringReader;
import java.io.StringWriter;

/* loaded from: XmlUtilForDataStream.class */
public class XmlUtilForDataStream {
    public static String convertToXml(Object obj) {
        StringWriter sw = new StringWriter();
        try {
            Marshaller marshaller = JAXBContext.newInstance(new Class[]{obj.getClass()}).createMarshaller();
            marshaller.setProperty("jaxb.formatted.output", Boolean.TRUE);
            marshaller.marshal(obj, sw);
        } catch (JAXBException e) {
            e.printStackTrace();
        }
        return sw.toString();
    }

    /*  JADX ERROR: JadxRuntimeException in pass: BlockProcessor
        jadx.core.utils.exceptions.JadxRuntimeException: Unreachable block: B:4:0x002f
        	at jadx.core.dex.visitors.blocks.BlockProcessor.checkForUnreachableBlocks(BlockProcessor.java:86)
        	at jadx.core.dex.visitors.blocks.BlockProcessor.processBlocksTree(BlockProcessor.java:52)
        	at jadx.core.dex.visitors.blocks.BlockProcessor.visit(BlockProcessor.java:44)
        */
    public static void convertToXml(Object r5, String r6) {
        /*
            r0 = 1
            java.lang.Class[] r0 = new java.lang.Class[r0]     // Catch: JAXBException -> 0x0042
            r1 = r0
            r2 = 0
            r3 = r5
            java.lang.Class r3 = r3.getClass()     // Catch: JAXBException -> 0x0042
            r1[r2] = r3     // Catch: JAXBException -> 0x0042
            javax.xml.bind.JAXBContext r0 = javax.xml.bind.JAXBContext.newInstance(r0)     // Catch: JAXBException -> 0x0042
            r7 = r0
            r0 = r7
            javax.xml.bind.Marshaller r0 = r0.createMarshaller()     // Catch: JAXBException -> 0x0042
            r8 = r0
            r0 = r8
            java.lang.String r1 = "jaxb.formatted.output"
            java.lang.Boolean r2 = java.lang.Boolean.TRUE     // Catch: JAXBException -> 0x0042
            r0.setProperty(r1, r2)     // Catch: JAXBException -> 0x0042
            r0 = 0
            r9 = r0
            java.io.FileWriter r0 = new java.io.FileWriter     // Catch: IOException -> 0x002f, JAXBException -> 0x0042
            r1 = r0
            r2 = r6
            r1.<init>(r2)     // Catch: IOException -> 0x002f, JAXBException -> 0x0042
            r9 = r0
            goto L_0x0036
        L_0x002f:
            r10 = move-exception
            r0 = r10
            r0.printStackTrace()     // Catch: JAXBException -> 0x0042
        L_0x0036:
            r0 = r8
            r1 = r5
            r2 = r9
            r0.marshal(r1, r2)     // Catch: JAXBException -> 0x0042
            goto L_0x0047
        L_0x0042:
            r7 = move-exception
            r0 = r7
            r0.printStackTrace()
        L_0x0047:
            return
        */
        throw new UnsupportedOperationException("Method not decompiled: com.tdqy.cadre.modular.profess.utils.XmlUtilForDataStream.convertToXml(java.lang.Object, java.lang.String):void");
    }

    public static Object convertXmlStrToObject(Class clazz, String xmlStr) {
        Object xmlObject = null;
        try {
            xmlObject = JAXBContext.newInstance(new Class[]{clazz}).createUnmarshaller().unmarshal(new StringReader(xmlStr));
        } catch (JAXBException e) {
            e.printStackTrace();
        }
        return xmlObject;
    }

    /*  JADX ERROR: JadxRuntimeException in pass: BlockProcessor
        jadx.core.utils.exceptions.JadxRuntimeException: Unreachable block: B:5:0x0026
        	at jadx.core.dex.visitors.blocks.BlockProcessor.checkForUnreachableBlocks(BlockProcessor.java:86)
        	at jadx.core.dex.visitors.blocks.BlockProcessor.processBlocksTree(BlockProcessor.java:52)
        	at jadx.core.dex.visitors.blocks.BlockProcessor.visit(BlockProcessor.java:44)
        */
    public Object convertXmlFileToObject(Class r6, String r7) {
        /*
            r5 = this;
            r0 = 0
            r8 = r0
            r0 = 1
            java.lang.Class[] r0 = new java.lang.Class[r0]     // Catch: JAXBException -> 0x003a
            r1 = r0
            r2 = 0
            r3 = r6
            r1[r2] = r3     // Catch: JAXBException -> 0x003a
            javax.xml.bind.JAXBContext r0 = javax.xml.bind.JAXBContext.newInstance(r0)     // Catch: JAXBException -> 0x003a
            r9 = r0
            r0 = r9
            javax.xml.bind.Unmarshaller r0 = r0.createUnmarshaller()     // Catch: JAXBException -> 0x003a
            r10 = r0
            r0 = 0
            r11 = r0
            java.io.FileReader r0 = new java.io.FileReader     // Catch: FileNotFoundException -> 0x0026, JAXBException -> 0x003a
            r1 = r0
            r2 = r7
            r1.<init>(r2)     // Catch: FileNotFoundException -> 0x0026, JAXBException -> 0x003a
            r11 = r0
            goto L_0x002d
        L_0x0026:
            r12 = move-exception
            r0 = r12
            r0.printStackTrace()     // Catch: JAXBException -> 0x003a
        L_0x002d:
            r0 = r10
            r1 = r11
            java.lang.Object r0 = r0.unmarshal(r1)     // Catch: JAXBException -> 0x003a
            r8 = r0
            goto L_0x0041
        L_0x003a:
            r9 = move-exception
            r0 = r9
            r0.printStackTrace()
        L_0x0041:
            r0 = r8
            return r0
        */
        throw new UnsupportedOperationException("Method not decompiled: com.tdqy.cadre.modular.profess.utils.XmlUtilForDataStream.convertXmlFileToObject(java.lang.Class, java.lang.String):java.lang.Object");
    }

    public void setXml(Object object, String name) {
        System.out.println("---将对象转换成File类型的xml Start---");
        convertToXml(object, "D:\\user.xml");
        System.out.println("---将对象转换成File类型的xml End---");
    }

    public Object getXml(Class clazz, Object object, String name) {
        return convertXmlStrToObject(clazz, name);
    }

    public static Object getDocument(HttpServletRequest request, Object object) {
        String xmlStr = null;
        XmlUtilForDataStream xml = new XmlUtilForDataStream();
        try {
            xmlStr = new SAXReader().read(request.getInputStream()).asXML();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return xml.getXml(object.getClass(), object, xmlStr);
    }

    public static String beanToXml(Object obj, Class<?> load) throws JAXBException {
        Marshaller marshaller = JAXBContext.newInstance(new Class[]{load}).createMarshaller();
        marshaller.setProperty("jaxb.formatted.output", true);
        marshaller.setProperty("jaxb.encoding", "UTF-8");
        StringWriter writer = new StringWriter();
        marshaller.marshal(obj, writer);
        return writer.toString();
    }
}
